/*
 * Created on Sat Sep 16 2017
 * 
 * Copyright (c) 2017 jianglinjie
 */
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _HttpMethod = require('../constants/HttpMethod');

var HttpMethod = _interopRequireWildcard(_HttpMethod);

var _ResponseType = require('../constants/ResponseType');

var ResponseType = _interopRequireWildcard(_ResponseType);

var _urijs = require('urijs');

var _urijs2 = _interopRequireDefault(_urijs);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var NetRequest = function () {
  function NetRequest(url, urlParam, body, headers) {
    var method = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : HttpMethod.GET;
    var responseType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ResponseType.JSON_TYPE;

    _classCallCheck(this, NetRequest);

    this.url = url;
    this.urlParam = urlParam || {};
    this.body = body || null;
    this.headers = headers || {};
    this.method = method;
    this.responseType = responseType;
  }

  _createClass(NetRequest, [{
    key: 'clone',
    value: function clone() {
      var request = new NetRequest(this.url, this.urlParam, this.body, this.headers, this.method, this.responseType);
      return request;
    }
  }, {
    key: 'requestUrl',
    get: function get() {
      var uri = new _urijs2.default(this.url);
      if (this.urlParam && Object.keys(this.urlParam).length) {
        uri.setSearch(this.urlParam);
      }

      return uri.toString();
    }
  }]);

  return NetRequest;
}();

exports.default = NetRequest;